package deviceGroup

import (
	"context"
	"devops-super/api/product/v1"
	"devops-super/internal/model/entity"
	"devops-super/internal/service"
	"github.com/gogf/gf/v2/os/gtime"
)

// GetPageLst 分页获取设备分组列表
func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.DeviceGroupGetPageLstReq) (res *v1.DeviceGroupGetPageLstRes, err error) {
	res = &v1.DeviceGroupGetPageLstRes{}
	res.PageLstRes, err = service.DeviceGroup().GetPageLst(ctx, req)
	return
}

// Add 新增设备分组
func (*ControllerV1) Add(ctx context.Context, req *v1.DeviceGroupAddReq) (res *v1.DeviceGroupAddRes, err error) {
	group := &entity.AppDeviceGroup{
		GroupKey:  req.GroupKey,
		Name:      req.Name,
		Purpose:   req.Purpose,
		Remark:    req.Remark,
		DeptId:    req.DeptId,
		ParentId:  req.ParentId,
		CreatedAt: gtime.Now(),
	}
	err = service.DeviceGroup().Add(ctx, group)
	return
}

// Upt 更新设备分组
func (*ControllerV1) Upt(ctx context.Context, req *v1.DeviceGroupUptReq) (res *v1.DeviceGroupUptRes, err error) {
	group := &entity.AppDeviceGroup{
		Id:        int64(req.Id),
		GroupKey:  req.GroupKey,
		Name:      req.Name,
		Purpose:   req.Purpose,
		Remark:    req.Remark,
		DeptId:    req.DeptId,
		ParentId:  req.ParentId,
		UpdatedAt: gtime.Now(),
	}
	err = service.DeviceGroup().Upt(ctx, group)
	return
}

// Del 删除设备分组
func (*ControllerV1) Del(ctx context.Context, req *v1.DeviceGroupDelReq) (res *v1.DeviceGroupDelRes, err error) {
	err = service.DeviceGroup().Del(ctx, req.Id)
	return
}

// GetOne 获取单条设备分组
func (*ControllerV1) GetOne(ctx context.Context, req *v1.DeviceGroupGetOneReq) (res *v1.DeviceGroupGetOneRes, err error) {
	res1, err := service.DeviceGroup().GetOne(ctx, req.Id)
	if err != nil {
		return
	}
	res = new(v1.DeviceGroupGetOneRes)
	res.Info = res1
	return
}

// GetOptions 获取设备分组选项
func (*ControllerV1) GetOptions(ctx context.Context, req *v1.DeviceGroupGetOptionsReq) (res *v1.DeviceGroupGetOptionsRes, err error) {
	res, err = service.DeviceGroup().GetOptions(ctx, req)
	return
}
